package com.zzyl.controller.manager;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(path = "/iot")
@Api(tags = "设备管理")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    @PostMapping(path = "/syncProductList")
    @ApiOperation("同步产品列表")
    public ResponseResult<Void> syncProductList() {
        deviceService.syncProductList();
        return ResponseResult.success();
    }

    @GetMapping(path = "/allProduct")
    @ApiOperation("获取所有产品")
    public ResponseResult<List<ProductVo>> allProduct() {
        List<ProductVo> productVos = deviceService.allProduct();
        return ResponseResult.success(productVos);
    }

    @PostMapping(path = "/RegisterDevice")
    @ApiOperation("注册设备")
    public ResponseResult<Void> registerDevice(@RequestBody DeviceDto deviceDto) {
        deviceService.registerDevice(deviceDto);
        return ResponseResult.success();
    }

    @GetMapping(path = "/pageQueryDevice")
    @ApiOperation("分页查询设备")
    public ResponseResult<PageResponse<DeviceVo>> pageQueryDevice(DevicePageQueryDto devicePageQueryDto){
        PageResponse<DeviceVo> pageResponse = deviceService.pageQueryDevice(devicePageQueryDto);
        return ResponseResult.success(pageResponse);
    }

    @PostMapping(path = "/QueryDeviceDetail")
    @ApiOperation("查询设备详情")
    public ResponseResult<DeviceVo> queryDeviceDetail(@RequestBody DeviceDto deviceDto){
        DeviceVo deviceVo = deviceService.queryDeviceDetail(deviceDto);
        return ResponseResult.success(deviceVo);
    }

    @PostMapping(path = "/UpdateDevice")
    @ApiOperation("修改设备备注名称")
    public ResponseResult<Void> updateDevice(@RequestBody DeviceDto deviceDto){
        deviceService.updateDevice(deviceDto);
        return ResponseResult.success();
    }

    @DeleteMapping(path = "/DeleteDevice")
    @ApiOperation("删除设备")
    public ResponseResult<Void> deleteDevice(@RequestBody DeviceDto deviceDto){
        deviceService.deleteDevice(deviceDto);
        return ResponseResult.success();
    }

    @PostMapping(path = "/QueryThingModelPublished")
    @ApiOperation("查询物模型")
    public ResponseResult<Map<String,String>> queryThingModelPublished(@RequestBody DeviceDto deviceDto){
        Map<String,String> thingModel = deviceService.queryThingModelPublished(deviceDto);
        return ResponseResult.success(thingModel);
    }

    @PostMapping(path = "/QueryDevicePropertyStatus")
    @ApiOperation("查询物模型状态信息")
    public ResponseResult<Map<String,Object>> queryDevicePropertyStatus(@RequestBody DeviceDto deviceDto){
        Map<String,Object> thingModel = deviceService.queryDevicePropertyStatus(deviceDto);
        return ResponseResult.success(thingModel);
    }
}
